package org.example.safe;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZerlindaLi create at 2021/3/30 14:32
 * @version 1.0.0
 * @description Folder
 */
public class Folder extends Directory{
    private List<Directory> dirs;

    private Integer level;

    public Folder(String name, Integer level) {
        super(name);
        this.level = level;
        this.dirs = new ArrayList<>();
    }


    @Override
    public void show() {
        System.out.println(this.name);
        for(Directory dir : dirs) {
            if(level != null) {
                for(int i = 0; i < level; i++) {
                    System.out.print(" ");
                }

                for(int i = 0; i < level; i++) {
                    if(i == 0) System.out.print("+");
                    System.out.print("-");
                }
            }
            dir.show();
        }
    }

    public boolean addChild(Directory dir) {
        return dirs.add(dir);
    }

    public boolean removeChild(Directory dir) {
        return dirs.add(dir);
    }

    public Directory get(Integer index) {
        return this.dirs.get(index);
    }

    public void list(){
        for(Directory dir : dirs){
            System.out.println(dir.name);
        }
    }

}
